package lianxi;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
import java.util.StringTokenizer;

import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class TextListener implements DocumentListener {
	JTextArea inputText,showText;
	   public void setInputText(JTextArea text) {
	      inputText = text;
	   }
	   public void setShowText(JTextArea text) {
	      showText = text;
	   } 
	   public void changedUpdate(DocumentEvent e) {
	      String str=inputText.getText(); 
	      String regex="[\\s\\d\\p{Punct}]+"; 
	      String words[]=str.split(regex); 
	      Arrays.sort(words);     
	      showText.setText(null); 
	      for(int i=0;i<words.length;i++)
	         showText.append(words[i]+",");
	   }
	   public void removeUpdate(DocumentEvent e) { 
	      changedUpdate(e);
	   }
	   public void insertUpdate(DocumentEvent e) { 
	      changedUpdate(e);
	   }
}